import { defineStore } from 'pinia'
import { ref , computed} from 'vue'
import axios from 'axios'
export const useChannelStore = defineStore('channel', () => {
    // state相关
    // 声明数据 state  
    const channelList = ref([]) 

    // 声明操作数据的方法 action
    const setChannelList = async () => {
        // 支持异步操作
        const {data: {data}} = await axios.get('http://geek.itheima.net/v1_0/channels')
        channelList.value = data.channels        
    }
    
    // 声明基于数据派生的计算属性 getter 
    const getChannelList = computed(() => channelList.value)

    return {
        channelList,
        setChannelList,
        getChannelList
    }
}, {
    persist: true // 开启持久化存储
})